<?php
include("../../tools/session.php");
include("../../tools/controls.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
$page_status = $_POST["page_status"];
$per_page = 10;
if (!$page_status)
{
   include("../../tools/mysql.php");
   db_connect();
   include("tpl-inc-wp.php");
   
   $sql = "SELECT ceil(count(notice_id)/" . $per_page . ") num FROM notice";
   $re = db_query_once($sql);	
   
   $tpl->assign("page_num", $re["num"]);
   $tpl->display($oa_tpl_path . "/default/notice_received.html");
}
// 如果 $page_status 为 1，那么显示 XML 数据
elseif ($page_status == 1)
{
   include("../../tools/mysql.php");
   db_connect();
   
   header("content-type: text/xml");
   echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   echo "<notice>\n";
   
   $page = $_POST["page"];
   $page = ($page == "" || $page <= 0) ? 1 : $page;
   
   $sql = "SELECT notice_id, title, author, addtime FROM notice ORDER BY addtime DESC";
   $re = db_query_page($sql, $page, $per_page);
   
   foreach ($re as $v)
	 {
		echo "<item>\n";
		echo "<id>" . $v["notice_id"] . "</id>\n";
		echo "<title><![CDATA[" . $v["title"] . "]]></title>\n";
		echo "<author><![CDATA[" . $v["author"] . "]]></author>\n";
		echo "<addtime><![CDATA[" . $v["addtime"] . "]]></addtime>\n";
		echo "</item>\n";
	 }
  
   echo "</notice>\n";
}
// 如果 $page_status 为 2，那么显示数据 XML
elseif ($page_status == 2)
{
   include("../../tools/mysql.php");
   db_connect();
   
   header("content-type: text/xml");
   echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   echo "<notice>\n";
   
   $notice_id = $_POST["notice_id"];
   
   $sql = "SELECT title, content FROM notice WHERE notice_id=" . $notice_id;
   $re = db_query_once($sql);
   
   echo "<title><![CDATA[" . $re["title"] . "]]></title>\n";
   echo "<content><![CDATA[" . $re["content"] . "]]></content>\n";
   
   echo "</notice>\n";
}
?>
